const conf = new (require('conf'))()
const chalk = require('chalk')
const TaskAPI = require('../api/task')
const {get} = require('lodash')

const Table = require('cli-table')

async function list(tag = '1') {
  const table = new Table({
    head: ['id', 'task', 'tag'],
    colWidths: [5, 30, 10],
    style: {compact: true, head: ['green']}
  });


  const taskAPI = new TaskAPI();
  const task = await taskAPI.list();
  const todoList = get(task, 'data.items', []);
  todoList.forEach((task, index) => {
    conf.set('task:' + index, task.id);
    table.push([index, task.text, task.done])
  })

  console.info(table.toString())
}

module.exports = list
